package com.sdrongyou.tms.service.impl;

import cn.zhxu.bs.BeanSearcher;
import cn.zhxu.bs.util.MapUtils;
import com.sdrongyou.tms.dto.DriverDO;
import com.sdrongyou.tms.dto.DriverVO;
import com.sdrongyou.tms.mapper.DriverMapper;
import com.sdrongyou.tms.service.DriverIService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class DriverIServiceImpl implements DriverIService {

    @Resource
    private DriverMapper driverMapper;

    @Resource
    private BeanSearcher beanSearcher;

    /**
     * 创建司机信息
     */
    @Override
    public int saveDriver(DriverDO driverDO) {
        return driverMapper.insert(driverDO);
    }

    /**
     * 更新司机信息
     */
    @Override
    public int updateDriver(DriverDO driverDO) {
        return driverMapper.updateById(driverDO);
    }

    /**
     * 删除司机
     */
    @Override
    public int deleteDriver(Long id) {
        return driverMapper.deleteById(id);
    }

    /**
     * 批量删除司机
     */
    @Override
    public int batchDeleteDriver(List<Long> ids) {
        return driverMapper.deleteByIds(ids);
    }

    /**
     * 分页查询
     */
    @Override
    public List<DriverVO> queryDriverPageList(DriverDO driverDO) {
        // 字段参数
        Map<String,Object> params = MapUtils.builder()
                .field("name", driverDO.getName())
                .op("ct")
                .build();
        return beanSearcher.searchList(DriverVO.class, params);
    }

    /**
     * 根据id查询司机信息
     */
    @Override
    public DriverVO queryDriverById(Long id) {
        Map<String,Object> params = MapUtils.builder()
                .field("id", id)
                .build();
        return beanSearcher.searchFirst(DriverVO.class, params);
    }

    /**
     * 查询所有司机列表
     */
    @Override
    public List<DriverVO> queryDriverDataList(DriverDO driverDO) {
        // 字段参数
        Map<String,Object> params = MapUtils.builder()
                .build();
        return beanSearcher.searchList(DriverVO.class, params);
    }
}
